package icu.lingjie.灵界;

import static icu.lingjie.util.ConfigUtil.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;

@Slf4j
@Data
public class 灵界类 {

    @Data
    private static class 灵界信息类 {
        int time;
    }

    public 灵界信息类 info;


    private void 生成一个随机的世界地图(){
        Random random = new Random();
        for (int i = 0; i < 灵界长度X; i++) {
            for (int j = 0; j < 灵界宽度Y; j++) {
                if (random.nextInt(32) == 1) {

                }
            }
        }
    }

    // 统计地图中点的数目
    private int getPointNum(){
        int sum = 0;
        for (int i = 0; i < 灵界长度X; i+=2) {
            for (int j = 0; j < 灵界宽度Y; j+=2) {
                sum += 0;
            }
        }
        return sum;
    }

    // 获取 x,y,z 为中心，共 80*80*80 范围的点
    public void getPointsForWeb(int x, int y, int w, int h, HttpServletResponse response){
        response.setContentType("application/octet-stream");
        try(ServletOutputStream sout = response.getOutputStream();
            BufferedOutputStream bout = new BufferedOutputStream(sout);
            DataOutputStream dout = new DataOutputStream(bout);) {
            // 循环，将一块的点返回
            for (int i = x; i < x + w; i++) {
                for (int j = y; j < y + h; j++) {
                    dout.writeInt(0);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
